package com.mjh.zhujianju.controller.party;

import com.livew.framework.base.controller.BaseController;
import com.livew.framework.base.service.BaseService;
import com.livew.framework.exception.XTBusinessException;
import com.livew.framework.page.PagedResult;
import com.livew.framework.pojo.AjaxResult;
import com.mjh.zhujianju.model.party.BuildingMeetingEO;
import com.mjh.zhujianju.service.party.BuildingMeetingService;
import com.mjh.zhujianju.vo.party.BuildingMeetingUserVO;
import com.mjh.zhujianju.vo.party.BuildingMeetingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author: Alex
 * @version: V1.0
 * @project: zhujianju
 * @package: com.mjh.zhujianju.controller.party
 * @description: description
 * @date: 2018/8/16
 * @time: 下午4:34
 */
@Controller()
@RequestMapping("party/meeting")
public class MeetingController extends BaseController<BuildingMeetingEO> {

    @Autowired
    private BuildingMeetingService buildingMeetingService;

    @Override
    protected BaseService<BuildingMeetingEO> getService() {
        return buildingMeetingService;
    }

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");


    @RequestMapping(value = "getPage", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult getPage(BuildingMeetingVO buildingMeetingVO) {
        PagedResult<BuildingMeetingVO> list = buildingMeetingService.findBuildingNewsPagination(buildingMeetingVO);
        return AjaxResult.getResult(list);
    }

    @RequestMapping(value="saveMeetingInfo",method=RequestMethod.POST)
    @ResponseBody
    public AjaxResult saveMeetingInfo(BuildingMeetingVO buildingMeetingVO) {
        if(buildingMeetingVO==null) {
            return AjaxResult.getResult(Boolean.FALSE, "参数错误" );
        }

        try {

            buildingMeetingService.saveInfo(buildingMeetingVO);

        }catch (XTBusinessException e) {
            e.printStackTrace();
            return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
        }
        return AjaxResult.getResult(Boolean.TRUE, "保存成功");
    }

    @RequestMapping(value = "editNews/{id}", method = RequestMethod.GET)
    public String editNews(@PathVariable("id") Long id, Model model) {
        BuildingMeetingVO buildingMeetingVO = buildingMeetingService.queryBuildingMeetingInfo(id);
        model.addAttribute("buildingMeeting", buildingMeetingVO);
        return "party/meeting/create";
    }

    @Override
    public AjaxResult findById(@PathVariable("id") Long id) {
        if (id == null) {
            return AjaxResult.getResult(Boolean.FALSE, "参数错误");
        }
        BuildingMeetingVO t = null;
        try {
            t =this.buildingMeetingService.getInfo(id);
        } catch (XTBusinessException e) {
            e.printStackTrace();
            return AjaxResult.getResult(Boolean.FALSE, e.getMessage());
        }
        return AjaxResult.getResult(t);
    }

    @RequestMapping(value = "detailMeeting/{id}", method = RequestMethod.GET)
    public String detailMeeting(@PathVariable("id") Long id, Model model) {
        BuildingMeetingVO buildingMeetingVO = buildingMeetingService.queryBuildingMeetingInfo(id);
        model.addAttribute("buildingMeeting", buildingMeetingVO);
        return "party/meeting/detail1";
    }

    @RequestMapping(value = "detailSign/{id}", method = RequestMethod.GET)
    public String detailSign(@PathVariable("id") Long id, Model model) {
        return "party/meeting/detail2";
    }

    @RequestMapping(value = "showSign", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult showSign(BuildingMeetingUserVO buildingMeetingUserVO) {
        PagedResult<BuildingMeetingUserVO> list = buildingMeetingService.findBuildingMeetingUsersPagination(buildingMeetingUserVO);
        return AjaxResult.getResult(list);
    }

}
